package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CheckItemServiceImpl implements com.itheima.service.CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;
    /**
     * 新增检查项
     * @param checkItem
     */

    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    //分页查询
    @Override
    public Map findPage(QueryPageBean queryPageBean) {
        Map map=new HashMap();
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<CheckItem> itemList = checkItemMapper.findPage(queryPageBean.getQueryString());
        PageInfo<CheckItem> pageInfo=new PageInfo<CheckItem>(itemList);
        map.put("itemList",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    //通过id删除检查项
    @Override
    public void deleteCheckItemById(Integer id) {
        checkItemMapper.deleteCheckItemById(id);
    }

    //编辑检查项
    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }

    //查询所有检查项
    @Override
    public List<CheckItem> findAll() {
       List<CheckItem> itemList= checkItemMapper.findAll();
        return itemList;
    }



}
